import unittest
from page.y_web_express_page import PageWebExpress
from parameterized import parameterized
from tools.y_get_data import get_express_add_data as get_add_data, \
    get_express_delete_data as get_delete_data, \
    get_cookies

url = 'http://192.168.8.222/admin.php'


class TestWebExpressAdd(unittest.TestCase):
    express_add = None

    @classmethod
    def setUpClass(cls):
        cls.express_add = PageWebExpress(url)
        cls.express_add.driver.add_cookie(get_cookies())  # 添加cookies
        cls.express_add.driver.refresh()  # 刷新界面
        cls.express_add.click_web_manager_a()
        cls.express_add.click_express_manager()
        cls.express_add.to_iframe()

    @classmethod
    def tearDownClass(cls):
        cls.express_add.driver.quit()

    @parameterized.expand(get_add_data())
    def test_express(self, data, expect):
        info = self.express_add.express_add_flow(*data)
        try:
            self.assertEqual(expect, info)
        except AssertionError:
            self.express_add.get_image('y')
            raise


class TestWebExpressDelete(unittest.TestCase):
    express_delete = None

    @classmethod
    def setUpClass(cls):
        cls.express_delete = PageWebExpress(url)
        cls.express_delete.driver.add_cookie(get_cookies())  # 添加cookies
        cls.express_delete.driver.refresh()  # 刷新界面
        cls.express_delete.click_web_manager_a()
        cls.express_delete.click_express_manager()
        cls.express_delete.to_iframe()

    @classmethod
    def tearDownClass(cls):
        cls.express_delete.driver.quit()

    @parameterized.expand(get_delete_data())
    def test_express(self, data, expect):
        info = self.express_delete.express_delete_flow(data)
        try:
            self.assertEqual(expect, info)
        except AssertionError:
            self.express_delete.get_image('y')
            raise
